Сегодня разберём полезную команду для работы с contextlib.suppress — удобный способ игнорировать определённые исключения без громоздкого try-except.
from contextlib import suppress
# Игнорируем FileNotFoundError при удалении файла with suppress(FileNotFoundError): import os os.remove("non_existent_file.txt")
Зачем это нужно: ✅ Упрощает код, когда вы хотите молча пропустить определённые ошибки. ✅ Например, удаление файла, который может не существовать, или обработка данных, где некоторые ключи могут отсутствовать.
Пример из реальной жизни:
data = {"name": "Alice"} with suppress(KeyError): print(data["age"]) # Не сломается, даже если ключа "age" нет
Сегодня разберём полезную команду для работы с contextlib.suppress — удобный способ игнорировать определённые исключения без громоздкого try-except.
from contextlib import suppress
# Игнорируем FileNotFoundError при удалении файла with suppress(FileNotFoundError): import os os.remove("non_existent_file.txt")
Зачем это нужно: ✅ Упрощает код, когда вы хотите молча пропустить определённые ошибки. ✅ Например, удаление файла, который может не существовать, или обработка данных, где некоторые ключи могут отсутствовать.
Пример из реальной жизни:
data = {"name": "Alice"} with suppress(KeyError): print(data["age"]) # Не сломается, даже если ключа "age" нет
Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.
China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.
Библиотека питониста | Python Django Flask from ca